package com.qf.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.util.Properties;

public class DruidUtils {

    //阿里的Druid数据源
    private static DruidDataSource druidDataSource;

    public static void initDataSource(String druidConfigName) {
        try {
            Properties properties = new Properties();
            properties.load(DruidUtils.class.getClassLoader().getResourceAsStream(druidConfigName));
            druidDataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //用于Apache的common-DbUtils获取数据源
    public static DataSource getDataSource() {
        return druidDataSource;
    }
}
